using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using QianJin.Views;
using QianJin.Models;

namespace QianJin.Controllers
{
    public class ProductListController : BaseController
    {
        //
        // GET: /ProductList/

        public ActionResult Show(string categoryId)
        {
            if (string.IsNullOrEmpty(categoryId))
            {
                categoryId = ProductDatabase.Instance.GetAllCategories().First().id;
            }

            var currentCategory = ProductDatabase.Instance.GetCategory(categoryId);

            return View(
                string.IsNullOrEmpty(currentCategory.specialview) ? "ProductList" : currentCategory.specialview,
                new ProductListViewData()
                {
                     Products = ProductDatabase.Instance.GetAllProductsFromCategory(categoryId),
                     User = this.CurrentUser,
                     ProductCategories = ProductDatabase.Instance.GetAllCategories(),
                     CurrentCategory = currentCategory
                }
            );
        }

        public ActionResult ShowProduct(string prodId, string categoryId)
        {
            var prod = ProductDatabase.Instance.GetProduct(prodId);

            return View(
                "ProductDetail",
                new ProductDetailViewData()
                {
                    User = this.CurrentUser,
                    Product = prod,
                    ProductCategories = ProductDatabase.Instance.GetAllCategories(),
                    CurrentCategory = ProductDatabase.Instance.GetCategory(categoryId)
                }
                );
        }

    }
}
